import React from 'react'

export default class extends React.Component {

  state = {
    count: 0
  }

  // 合成事件中是异步
  // 钩子函数中的是异步

  // 原生事件中是同步
  // setTimeout中是同步

  // 钩子函数中的是异步
  componentDidMount() {
    this.setState({count: this.state.count + 1})
    console.log('state1', this.state.count) // 0

    this.setState({count: this.state.count + 1})
    console.log('state2', this.state.count) // 0

    setTimeout(() => {
      this.setState({count: this.state.count + 1})
      console.log('state3', this.state.count) // 2

      this.setState({count: this.state.count + 1})
      console.log('state4', this.state.count) // 3
    }, 0)

    // 0 0 2 3
  }

  render() {
    return (
      <div>
        <h1>34567890</h1>
      </div>
    )
  }
}